package com.turing.post.cardmanagement.impl;

import java.math.BigInteger;

import javax.ejb.EJB;
import javax.ejb.Local;
import javax.ejb.Remote;
import javax.ejb.Stateless;

import com.turing.post.cardmanagement.util.AppCardFaceAssoc;
import com.turing.post.cardmanagement.util.AppCardFaceAssocBusiness;
import com.turing.post.cardmanagement.util.AppCardFaceAssocDao;
import com.turing.post.common.util.SysOperLog;
import com.turing.post.common.util.SysOperLogDao;
import com.turing.post.util.PCPSApplicationException;
import com.turing.post.util.PCPSWebInput;

/**
 * 应用卡面关联
 * 
 * @author lj
 * @Apr 10, 2013
 */
@Stateless(mappedName = "cardmanagement.impl.AppCardFaceAssocBusinessImpl")
@Remote
@Local
public class AppCardFaceAssocBusinessImpl implements AppCardFaceAssocBusiness {

	@EJB(mappedName = "cardmanagement.impl.AppCardFaceAssocDaoImpl")
	private AppCardFaceAssocDao appCardFaceAssocDaoImpl;

	@EJB(mappedName = "common.impl.SysOperLogDaoImpl")
	private SysOperLogDao sysOperLogDaoImpl;

	/**
	 * 异常抛出方法
	 * 
	 * @param error
	 * @throws PCPSApplicationException
	 */
	@SuppressWarnings("unused")
	private void errException(String error) throws PCPSApplicationException {
		throw new PCPSApplicationException(
				PCPSApplicationException.ERRCODE_CATEGORY_APPLICATION, "",
				error);
	}

	@Override
	public void bindCardApply(PCPSWebInput input, BigInteger cardId,
			AppCardFaceAssoc[] acfas) throws PCPSApplicationException {
		/**
		 * 参数合法性检查
		 */
		if (input.getOperId() == null) {
			errException("登录用户为空!");
		}
		if (cardId == null) {
			errException("获取卡ID失败！");
		}

		// 日志记录
		sysOperLogDaoImpl.insertSysOperLogInfo(input, SysOperLog.operType_Add,
				"绑定卡应用", "cardID:" + cardId);
		appCardFaceAssocDaoImpl.remove(cardId);
		for (int i = 0; i < acfas.length; i++) {
			appCardFaceAssocDaoImpl.insert(acfas[i]);
		}
	}

}
